<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html 	xmlns="http://www.w3.org/1999/xhtml"
		xmlns:f="http://java.sun.com/jsf/core"	
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:p="http://primefaces.prime.com.tr/ui">


<h:head>
	<title>Admin List of questions</title>
	
	<link type="text/css" rel="stylesheet" href="styles/cupertino/skin.css"/>
	<link type="text/css" rel="stylesheet" href="styles/common.css"/>

</h:head>

<h:body>  		
<h:form id="form">  
  
    <p:panel header="Question" toggleable="true">
    	<h:panelGrid columns="7" id="actionButtons">
            <p:commandButton value="New" action="#{questionListBean.reinitQuestion}" update="questionView,questionsList,answList" />  
            <p:commandButton value="Save" update="questionView,questionsList,answList" 
            	action="#{questionListBean.saveQuestion}">
            </p:commandButton>
            
            <p:separator style="width:2px;height:20px" />
                        
            <p:commandButton value="Total Delete" update="questionView,questionsList,answList" 
            	action="#{questionListBean.deleteQuestion}">
            </p:commandButton>
            <p:commandButton value="Mark Deleted" update="questionView,questionsList,answList" 
            	action="#{questionListBean.markQuestionDeleted}">
            </p:commandButton>        
            
            <p:separator style="width:2px;height:20px" />
            
            <p:commandButton value="Add answer" action="#{questionListBean.newAnswer}" update="form:answList">							
					<p:collector value="#{questionListBean.answer}" addTo="#{questionListBean.question.answers}" />
			</p:commandButton>    	
    	</h:panelGrid>  
    	
        <h:panelGrid columns="3" id="questionView">  
            <h:outputLabel value="Text : *" for="que_txt"/>  
            <h:inputText id="que_txt" style="width:500px"  
                            value="#{questionListBean.question.txt}" required="true"/>
            <p:message for="que_txt"/>                  
              
            
        </h:panelGrid>  
        
		<p:dataTable var="answ" value="#{questionListBean.question.answers}" id="answList" style="width:600px">  
	  
	        <f:facet name="header">  
	            Answers (options)  
	        </f:facet>  
	  
	  
	        <p:column headerText="Text" style="width:300px">  
	            <p:cellEditor>  
	                <f:facet name="output">  
	                    <h:outputText value="#{answ.txt}" />  
	                </f:facet>  
	                <f:facet name="input">  
	                    <h:inputText value="#{answ.txt}" style="width:100%"/>  
	                </f:facet>  
	            </p:cellEditor>  
	        </p:column>
	        
            <p:column style="width:60px">  
                <f:facet name="header">  
                    <h:outputText value="Pop" />  
                </f:facet>  
                <h:outputText value="#{answ.pop}" />  
            </p:column>	        
	  					  					  
	        <p:column headerText="Edit" style="width:60px">  
	            <p:rowEditor />  
	        </p:column> 
	         
            <p:column >  
                <f:facet name="header">  
                    <h:outputText value="Operation" />  
                </f:facet>	                
                <p:commandButton value="Remove" update="form:answList">
                	<p:collector value="#{answ}" removeFrom="#{questionListBean.question.answers}" />		
                </p:commandButton>			

            </p:column>  					        
	  
	    </p:dataTable>        
    </p:panel>  
    	
	<h:outputText value="show deleted"/>
      
    <p:outputPanel id="questionsList">  
        <p:dataTable value="#{questionListBean.questions}" var="qstn">  
  
            <p:column style="width:32px">  
            	<p:commandButton value="select" update="form:questionView,form:answList">  
                	<f:setPropertyActionListener value="#{qstn}"  
                    	target="#{questionListBean.question}" />  
            	</p:commandButton>  
        	</p:column> 
  
            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Question" />  
                </f:facet>  
                <h:outputText value="#{qstn.txt}" />  
            </p:column>  
  
            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Pop" />  
                </f:facet>  
                <h:outputText value="#{qstn.pop}" />  
            </p:column>  
  
            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Created" />  
                </f:facet>  
                <h:outputText value="#{qstn.dtCreate}" />  
            </p:column>  

            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Deleted" />  
                </f:facet>  
                <h:outputText value="#{qstn.dtDelete}" />  
            </p:column>              
  
        </p:dataTable>  
    </p:outputPanel>  
  
</h:form> 	     
 		
 
</h:body>
</html>